#!/bin/bash

#clean the data file
echo \#start >figure_on.dat
echo \#start >figure_off.dat

#run the simulation 10 times
#simulation_red minthrsh wait_value
simulation_red()
{ # $1 is the first parameter of simulation()
n1=$1
n2=$2
for ((simulation_i=1; simulation_i<=10; simulation_i++ )) do
	#red.tcl minthresh seed wait_value
	ns red.tcl $n1 $simulation_i $n2
done
}

#run the simulation with differen minthresh siz
for ((minthresh_i=1; minthresh_i<=50; minthresh_i=minthresh_i+1 )) do
	#simulation_red minthrsh wait_value
	simulation_red $minthresh_i true >temp_data
	cat temp_data | awk 'BEGIN{delay=0; throughput=0} {if ($2=="delay"){delay=delay+$5}; 
 			if ($2=="throughput"){throughput=throughput+$5}} 
			END{print 100*(delay/10)/0.017, (throughput/10)/45.0}' >> figure_on.dat
done

for ((minthresh_i=1; minthresh_i<=50; minthresh_i=minthresh_i+1 )) do
	#simulation_red minthrsh wait_value
	simulation_red $minthresh_i false >temp_data
	cat temp_data | awk 'BEGIN{delay=0; throughput=0} {if ($2=="delay"){delay=delay+$5}; 
 			if ($2=="throughput"){throughput=throughput+$5}} 
			END{print 100*(delay/10)/0.017, (throughput/10)/45.0}' >> figure_off.dat
done

#plot the graph
gnuplot figure8.plt
